import {
  getBasicUserInfo,
  updateBasicInfo,
  selectUserBalance,
  selectAllOrders,
  realNameAuthentication, getRealStat
} from '@/api/personCenter'

const personCenter = {
  actions: {
    getBasicUserInfo ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        getBasicUserInfo(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    updateBasicInfo ({ commit }, basicInfo) {
      const userId = basicInfo.userId
      return new Promise((resolve, reject) => {
        updateBasicInfo(userId, basicInfo.nickname, basicInfo.email, basicInfo.gender, basicInfo.birthday, basicInfo.userDescription).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    selectUserBalance ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        selectUserBalance(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    selectAllOrders ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        selectAllOrders(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    RealNameAuthentication ({ commit }, realNameInfo) {
      const userId = realNameInfo.userId
      return new Promise((resolve, reject) => {
        realNameAuthentication(userId, realNameInfo.realName, realNameInfo.idCardNumber).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    GetRealStat ({ commit }, userId) {
      return new Promise((resolve, reject) => {
        getRealStat(userId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default personCenter
